﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SHVS.DisplayData;
using VLIB28D.Geometry3D;

namespace GMPP.utils
{
    public class Collision
    {
        private const double Epsilon = 0.003;

        public static float TestIntersionPlane(Triangle5D plane, Vector3D ray,Point3D start)
        {
            var planeNormal = plane.UnitNormalVector();
            var p = plane[0];
            double dotProduct = Vector3D.DotProduct(ray, planeNormal);         // Dot Product Between Plane Normal And Ray Direction 

            // Determine If Ray Parallel To Plane
            if (Math.Abs(dotProduct - 0) < Epsilon)
                return -1; 
            var distance = Convert.ToSingle((planeNormal.X*(p.X - start.X) + planeNormal.Y*(p.Y - start.Y) + planeNormal.Z*(p.Z - start.Z))/(ray.X*planeNormal.X+ray.Y*planeNormal.Y+ray.Z*planeNormal.Z));
            return distance;
        }
    }
}
